import type { CSSProperties, ExtractPropTypes, PropType } from 'vue'
import type { IndexType, SizeType, CellRendererParams, RowRendererParams } from './types'

export const gridProps = {
  width: {
    type: Number,
    required: true
  },
  height: {
    type: Number,
    required: true
  },
  headerHeight: {
    type: Number,
    required: true
  },
  columnCount: {
    type: Number,
    required: true
  },
  leftColumnCount: {
    type: Number,
    default: 0
  },
  rightColumnCount: {
    type: Number,
    default: 0
  },
  rowCount: {
    type: Number,
    required: true
  },
  overscanColumnCount: {
    type: Number
  },
  overscanRowCount: {
    type: Number
  },
  columnWidth: {
    type: Function as PropType<SizeType>,
    required: true
  },
  rowHeight: {
    type: Function as PropType<SizeType>,
    required: true
  },
  estimatedColumnWidth: {
    type: Number
  },
  estimatedRowHeight: {
    type: Number
  },
  initialScrollLeft: {
    type: Number,
    default: 0
  },
  initialScrollTop: {
    type: Number,
    default: 0
  },
  cellKey: {
    type: Function as PropType<(params: IndexType) => string>,
    default: ({ rowIndex, columnIndex }: IndexType) => `${rowIndex}:${columnIndex}`
  },
  headerCellKey: {
    type: Function as PropType<(params: IndexType) => string>,
    default: ({ rowIndex, columnIndex }: IndexType) => `${rowIndex}:${columnIndex}`
  },
  cellRenderer: {
    type: Function as PropType<(params: CellRendererParams) => JSX.Element | null>,
    required: true
  },
  headerCellRenderer: {
    type: Function as PropType<(params: CellRendererParams) => JSX.Element | null>,
    required: true
  },
  rowRenderer: {
    type: Function as PropType<(params: RowRendererParams) => JSX.Element>,
    required: true
  },
  style: {
    type: Object as PropType<CSSProperties>,
    default: () => ({})
  },
  showHeader: {
    type: Boolean,
    default: true
  },
  enableHorizontal: {
    type: Boolean,
    default: false
  },
  enableVertical: {
    type: Boolean,
    default: true
  }
} as const

export type GridProps = ExtractPropTypes<typeof gridProps>
